package com.buba.customer.controller;

import com.buba.customer.pojo.CustomerLoginLog;
import com.buba.customer.service.CustomerLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 日志控制层
 */
@Controller
@RequestMapping("/CustomerLoginLog")
public class CustomerLoginLogController {
    private CustomerLoginLogService customerLoginLogService;

    /**
     * 删除用户日志方法
     * @param ids
     * @return
     */
    @RequestMapping("/delCustomerLoginLog.do")
    @ResponseBody
    public Map<String,Object> delCustomerLoginLog(String ids){
        Map<String,Object> map = new HashMap<>();
        String[] split = ids.split(",");
        Integer count = customerLoginLogService.delCustomerLoginLog(split);
        map.put("msg","删除了"+count+"条数据");
        return map;
    }
    /**
     * 查询日志功能
     * @param page 当前页
     * @param limit 每页显示条数
     * @return
     */
    @RequestMapping("/selCustomerLoginLog.do")
    @ResponseBody
    public Map<String,Object> selCustomerLoginLog(Integer customerId, String startTime, String endTime, Integer page, Integer limit){
        Map<String,Object> map = new HashMap<>();
        map.put("customerId",customerId);
        map.put("startTime",startTime);
        map.put("endTime",endTime);

        //查询总条数，查询当前页的数据
        Long count = customerLoginLogService.selCount(map);
        //把分页参数携带过去
        map.put("page",(page-1) * limit);
        map.put("limit",limit);

        List<CustomerLoginLog> list = customerLoginLogService.selCustomerLoginLog(map);

        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",list);
        return map;
    }





    public CustomerLoginLogService getCustomerLoginLogService() {
        return customerLoginLogService;
    }
    @Autowired
    public void setCustomerLoginLogService(CustomerLoginLogService customerLoginLogService) {
        this.customerLoginLogService = customerLoginLogService;
    }
}
